package com.example.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class ScheduledJobService {

    @Async // 结合一起使用， 避免调度阻塞
    @Scheduled(cron = "0/1 * * * * ?")
    public void executeScheduledJob1() {
        log.info("executeScheduledJob1 Scheduled job executed at {}", LocalDateTime.now());
    }

    @Async
    @Scheduled(cron = "0/1 * * * * ?")
    public void executeScheduledJob2() {
        log.info("executeScheduledJob2 Scheduled job executed at {}", LocalDateTime.now());
    }

    @Async
    @Scheduled(cron = "0/1 * * * * ?")
    public void executeScheduledJob3() {
        log.info("executeScheduledJob3 Scheduled job executed at {}", LocalDateTime.now());
    }

    @Async
    @Scheduled(cron = "0/1 * * * * ?")
    public void executeScheduledJob4() {
        log.info("executeScheduledJob4 Scheduled job executed at {}", LocalDateTime.now());
    }

}
